package com.example.unisys.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.unisys.entity.School;
import com.example.unisys.dao.SchoolMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class SchoolService extends ServiceImpl<SchoolMapper,School> {



    public int insert(School school){
        return baseMapper.insert(school);
    }

   public int insertSelective(School school){
        return baseMapper.insertSelective(school);
    }

    public  int update(School school){
        return baseMapper.update(school);
    }

    public School getById(int school_id){
        return baseMapper.getById(school_id);
    }


    public int getSchoolByMain(String main_school){
        return baseMapper.getSchoolByMain(main_school);
    }

    /**
     * 跟据主校和分校获取学校
     * @param main_school
     * @param sub_school
     * @return
     */
    public School getSchool(String main_school,String sub_school){
        QueryWrapper<School> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(School::getMain_school,main_school).eq(School::getSub_school,sub_school);
        return baseMapper.selectOne(queryWrapper);
//        return baseMapper.getSchool(main_school,sub_school);
    }

    /**
     * 获取学校列表
     * @param hs
     * @return
     */
    public List<School> getAllSchools(HashMap<String, Object> hs) {
        return baseMapper.getAllSchools(hs);
    }

    /**
     * 获取学校总数
     * @return
     */
    public int getAllSchoolSum(){
        return baseMapper.selectCount(new QueryWrapper<>());
//        return baseMapper.getAllSchoolSum();
    }


    public int deleteSchool(HashMap<String, Object> hs) {
        return baseMapper.deleteSchool(hs);
    }

    public ArrayList<String> getMainSchools() {
        return baseMapper.getMainSchools();
    }

    public ArrayList<String> getSubSchools(String main_school) {
        return baseMapper.getSubSchools(main_school);
    }
}
